package com.solver.demo.rscoket.v2.config;

import io.rsocket.transport.netty.client.TcpClientTransport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.rsocket.RSocketRequester;
import reactor.util.retry.Retry;

import java.time.Duration;

/**
 * @author：fangn
 * @since：2025/4/2
 */
@Configuration
public class RSocketConfig {
    @Value("${rsocket.server.host:localhost}")
    private String host;

    @Value("${rsocket.server.port:8081}")
    private int port;

    @Bean
    public RSocketRequester requester(RSocketRequester.Builder builder) {
        return builder
                .rsocketConnector(conn -> conn
                        .reconnect(Retry.fixedDelay(3, Duration.ofSeconds(2))) // 自动重连‌:ml-citation{ref="3,6" data="citationList"}
                )
                .transport(TcpClientTransport.create(host, port));
    }
}
